function InsertionSort takes integer left , integer right returns nothing
	local integer array list
	local integer size = 6
	local integer end = 0
	local integer pre = 0
	local integer temp = 0
	local string s = null
	local integer i = 0
	//--
	set list[0] = 8
	set list[1] = 7
	set list[2] = 6
	set list[3] = 5
	set list[4] = 4
	set list[5] = 3
	//--
	set end = 0
	loop
	set end = end + 1
	exitwhen end >= size
		set pre = end - 1
		loop
			if list[pre] > list[pre + 1] then
				set temp = list[pre]
				set list[pre] = list[pre + 1]
				set list[pre + 1] = temp
			else
				set pre = -1
			endif
		set pre = pre - 1
		exitwhen pre < 0
		endloop
	
	endloop
	//--display
	set i = 0
	loop
		set s = s + " " + I2S(list[i])
		
	set i = i + 1
	exitwhen i >= size
	endloop
	call BJDebugMsg(s)
endfunction

function Trig_ComputePriority_Actions takes nothing returns nothing
	local integer playerId = 0
	local integer end = 0
	local integer pre = 0
	local unit temp = null
	local integer i = 0
	//--
	//清空
	set i = 0
	loop	
	exitwhen i >= udg_TargetPriorityListSize
		set udg_TargetPriorityList[i] = null
	set i = i + 1
	endloop
	//--
	//放入倖存者
	set udg_TargetPriorityListSize = 0
	loop
	exitwhen playerId >= udg_MaxPlayerAmount
		if udg_Survivors[playerId] != null and GetUnitState(udg_Survivors[playerId] , UNIT_STATE_LIFE) >= 0.0 then
			set udg_TargetPriorityList[udg_TargetPriorityListSize] = udg_Survivors[playerId]
			set udg_TargetPriorityListSize = udg_TargetPriorityListSize + 1
		endif
	set playerId = playerId + 1
	endloop
	//--
	//插入排序
	set end = 0
	loop
	set end = end + 1
	exitwhen end >= udg_TargetPriorityListSize
		set pre = end - 1
		loop
			if GetUnitState(udg_TargetPriorityList[pre] , UNIT_STATE_LIFE) > GetUnitState(udg_TargetPriorityList[pre + 1] , UNIT_STATE_LIFE) then
				set temp = udg_TargetPriorityList[pre]
				set udg_TargetPriorityList[pre] = udg_TargetPriorityList[pre + 1]
				set udg_TargetPriorityList[pre + 1] = temp
			else
				set pre = -1
			endif
		set pre = pre - 1
		exitwhen pre < 0
		endloop
	endloop
	//--
	set temp = null
endfunction

//===========================================================================
function InitTrig_ComputePriority takes nothing returns nothing
	set gg_trg_ComputePriority = CreateTrigger()
	call TriggerRegisterTimerEventPeriodic(gg_trg_ComputePriority , 2.13)
	call TriggerAddAction(gg_trg_ComputePriority , function Trig_ComputePriority_Actions)
endfunction